$(function(){
	initPages();
	window.onresize = function () {
		initPages();
	};
	pageBtns();
	getUserInfo();
});
function initPages(){
	var winH = document.documentElement.clientHeight || document.body.clientHeight;
	var bodyH = winH - $(".index-head").height() - $(".footer").height()-5;
	$(".index-body").height(bodyH);
}
function getUserInfo(){
	var seachUrl = decodeURI(window.location.search);
	var paramStr = seachUrl.substring(1);
	params = paramStr.split("&");
	var parm = {};
	for(var i = 0; i < params.length; i++){
		var key = params[i].split("=")[0];
		var value = params[i].split("=")[1];
		parm[key] = value;
	}
	for(var key in parm){
		if(parm[key] == "" || parm[key] == undefined || parm[key] == null){
			window.location.href = encodeURI("mlogin.html");
			return false;
			break;
		}
	}
	$("#user-name").text(substr(parm.username,4)).attr("title",parm.username).attr("key",parm.userkey).attr("code",parm.usercode).attr("usertype",3);
	$("#user-head").attr("src","../"+ ServiceName + parm.headimg);
}
function substr(str,len){
	if(str != undefined){
		if(str.length > len){
			str = str.substring(0,len-1)+"...";
			return str;
		}else{
			return str;
		}
	}else{
		return "";
	}
}
function pageBtns(){
	$(".head-menu").click(function(){
		$(".head-menu").removeClass("head-menu-select");
		if($(this).text() == "学校管理"){
			$(this).addClass("head-menu-select");
			changePage(PageUrl.maintainSchoolUrl);
		}else if($(this).text() == "统计管理"){
			$(this).addClass("head-menu-select");
			changePage(PageUrl.maintainUrl);
		}else if($(this).text() == "用户管理"){
			$(this).addClass("head-menu-select");
			changePage(PageUrl.mainUserManagerUrl);
		}
	});
	
	$(".logout-btns").click(function(){
		window.location.href = encodeURI("mlogin.html");
	});
	
	$(".person-set-btns").click(function(){
		var usercode = $("#user-name").attr("code");
		var userKey = $("#user-name").attr("key");
		var usertype = $("#user-name").attr("usertype");
		var url = "setting.html?usercode="+usercode+"&userkey="+userKey+"&usertype="+usertype;
		window.open(url);
	});
	
	$(".user-info").mouseover(function(){
		$("#navigate").show();
	});
	
	$(".sys-menu").mouseover(function(){
		$("#navigate").hide();
	});
	
	$(".index-logo").mouseover(function(){
		$("#navigate").hide();
	});

	$(".index-body").mouseover(function(){
		$("#navigate").hide();
	});
	
	$(".logout-btns").mouseover(function(){
		$(".logout-btns").addClass("logout-btns-select");
	});
	
	$(".logout-btns").mouseout(function(){
		$(".logout-btns").removeClass("logout-btns-select");
	});
	
	$(".person-set-btns").mouseover(function(){
		$(".person-set-btns").addClass("person-set-btns-select");
	});
	
	$(".person-set-btns").mouseout(function(){
		$(".person-set-btns").removeClass("person-set-btns-select");
	});
	
	
	$(".user-info").mouseout(function(){
		$("#navigate").mouseover(function(){
			$("#navigate").show();
		});
		
		$("#navigate").mouseout(function(){
			$("#navigate").hide();
		});
	});
	
}
function changePage(pageurl){
	$("#main-body").attr("src",pageurl);
}

